package com.zking.ssm.controller;

import com.zking.ssm.model.HotelSeller;
import com.zking.ssm.model.HotelSellerEmployee;
import com.zking.ssm.service.IHotelSellerEmployeeService;
import com.zking.ssm.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/HotelSellerEmployee")
public class HotelSellerEmployeeController {

    @Autowired
    private IHotelSellerEmployeeService hotelSellerEmployeeService;

    @RequestMapping("/add")
    public Map<String,Object> add(HotelSellerEmployee hotelSellerEmployee){
        int n = hotelSellerEmployeeService.insert(hotelSellerEmployee);
        Map<String,Object> map = new HashMap<>();
        if(n >= 0){
            map.put("code",0);
            map.put("message","增加成功");
        }else{
            map.put("code",-1);
            map.put("message","增加失败");
        }
        return map;
    }

    @RequestMapping("/del")
    public Map<String,Object> del(HotelSellerEmployee hotelSellerEmployee){
        int n = hotelSellerEmployeeService.deleteByPrimaryKey(hotelSellerEmployee.getId());
        Map<String,Object> map = new HashMap<>();
        if(n >= 0){
            map.put("code",0);
            map.put("message","删除成功");
        }else{
            map.put("code",-1);
            map.put("message","删除失败");
        }
        return map;
    }

    @RequestMapping("/update")
    public Map<String,Object> update(HotelSellerEmployee hotelSellerEmployee){
        int n = hotelSellerEmployeeService.updateByPrimaryKeySelective(hotelSellerEmployee);
        Map<String,Object> map = new HashMap<>();
        if(n >= 0){
            map.put("code",0);
            map.put("message","修改成功");
        }else{
            map.put("code",-1);
            map.put("message","修改失败");
        }
        return map;
    }

    @RequestMapping("/get")
    public Map<String,Object> get(HotelSellerEmployee hotelSellerEmployee){
        HotelSellerEmployee h = hotelSellerEmployeeService.selectByPrimaryKey(hotelSellerEmployee.getId());
        Map<String,Object> map = new HashMap<>();
        if(h != null){
            map.put("code",0);
            map.put("message","查询成功");
            map.put("request",h);
        }else{
            map.put("code",-1);
            map.put("message","查询失败");
        }
        return map;
    }

    @RequestMapping("/list")
    public Map<String,Object> list(HotelSellerEmployee hotelSellerEmployee, PageBean pageBean, HttpServletRequest request){
        pageBean.setRequest(request);
        pageBean.setRows(pageBean.getRows());
        pageBean.setPage(pageBean.getPage());
        pageBean.setTotal(pageBean.getTotal());
        List<HotelSellerEmployee> list = hotelSellerEmployeeService.selectAll(hotelSellerEmployee, pageBean);
        Map<String,Object> map = new HashMap<>();
        if(list.size() >= 0){
            map.put("code",0);
            map.put("message","查询成功");
            map.put("request",list);
            map.put("page",pageBean.getPage());
            map.put("rows",pageBean.getRows());
            map.put("total",pageBean.getTotal());
        }else{
            map.put("code",-1);
            map.put("message","查询失败");
        }
        return map;
    }
}
